<template>
  <div>
<van-datetime-picker
  v-model="currentDate"
  type="date"
  title="选择年月日"
  :min-date="minDate"
  :max-date="maxDate"
  @cancel="onCancel"
  @confirm="onConfirm"
/>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { updateUserProfile } from '@/api/user'
export default {
  // 选择单词,按下ctrl+shift+p打开编辑去控制面板,输入change case
  name: 'UpdateBirthday',
  props: {
    value: String
  },
  data () {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    onCancel () {
      this.$emit('close')
    },
    async onConfirm () {
      const birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
      console.log('birthday', birthday)
      // 发请求
      await updateUserProfile({ birthday })
      // 提示成功
      this.$toast.success('修改成功')
      // 修改数据
      this.$emit('input', birthday)
      // 关闭弹层
      this.$emit('close')
    }
  }
}
</script>

<style lang="less" scoped>

</style>
